package com.zhijian.warehouse.manage.controller.app;

import com.zhijian.response.annotation.Response;
import com.zhijian.util.page.Page;
import com.zhijian.warehouse.manage.entity.vo.request.AppStoreSearchVo;
import com.zhijian.warehouse.manage.entity.vo.request.StoreAllotRecordProductSearchVoWithStore;
import com.zhijian.warehouse.manage.entity.vo.request.StoreSearchVo;
import com.zhijian.warehouse.manage.entity.vo.response.StoreVo;
import com.zhijian.warehouse.manage.service.StoreAllotRecordService;
import com.zhijian.warehouse.manage.service.StoreService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * 库存管理 控制层
 *
 * @author auto
 * @version 1.0
 * @date 2024-10-27 13:42:54
 */
@Slf4j
@Controller
@Api(tags = "app库存管理")
@RequestMapping("/app")
public class AppStoreController {

    @Autowired
    private StoreService service;

    @Autowired
    private StoreAllotRecordService storeAllotRecordService;

    /**
     * 分页查询
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/store/page")
    @ApiOperation("分页查询")
    public Page<StoreVo> selectByAppStoreSearchVo(@RequestBody(required = false) AppStoreSearchVo param) {
        if (param == null)
            param = AppStoreSearchVo.builder().build();
        log.info("{} - {}| selectByCondition info", this.getClass().getSimpleName(), param);
        StoreSearchVo searchVo = new StoreSearchVo();
        BeanUtils.copyProperties(param, searchVo);
        return service.selectPage(searchVo);
    }

    /**
     * 列表查询
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/store/list")
    @ApiOperation("列表查询")
    public List<StoreVo> selectList(@RequestBody(required = false) StoreSearchVo param) {
        if (param == null)
            param = StoreSearchVo.builder().build();
        log.info("{} - {}| query info", this.getClass().getSimpleName(), param);
        return service.selectList(param);
    }


    /**
     * 根据条形码 或者 rfid 查询库存产品
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/store/code/list")
    @ApiOperation("根据条形码 或者 rfid 查询库存产品")
    public List<StoreVo> selectListWithStore(@RequestBody StoreAllotRecordProductSearchVoWithStore param) {
        if (param == null)
            param = StoreAllotRecordProductSearchVoWithStore.builder().build();
        log.info("{} - {}| selectListWithStore info", this.getClass().getSimpleName(), param);
        return storeAllotRecordService.selectListWithStore(param);
    }

}
